package com.flea.hclv.service.impl;

import com.flea.hclv.model.dao.HGuideTravelGroupMapper;
import com.flea.hclv.model.entity.HGuideTravelGroup;
import com.flea.hclv.service.HGuideTravelGroupService;
import com.flea.hclv.util.ServerResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: project
 * @description: 导游和团关联
 * @author: shiliqiang
 * @create: 2018-12-19 15:06
 * @version: 1.0
 */
@Service
public class HGuideTravelGroupServiceImpl implements HGuideTravelGroupService {

    @Autowired
    private HGuideTravelGroupMapper hGuideTravelGroupMapper;

    @Override
    public ServerResponse<HGuideTravelGroup> deleteTravelGroupByGroupId(String groupId) {
        ServerResponse<HGuideTravelGroup> groupServerResponse = selectTravelGroupByGroupId(groupId);
        if (!groupServerResponse.isSuccess()){
            return groupServerResponse;
        }
        HGuideTravelGroup entity = groupServerResponse.getData();
        int row = hGuideTravelGroupMapper.deleteByPrimaryKey(entity.getId());
        if (row==1){
            return ServerResponse.createBySuccess();
        }
        return ServerResponse.createByError();
    }

    @Override
    public ServerResponse<HGuideTravelGroup> selectTravelGroupByGroupId(String groupId) {
        if (StringUtils.isEmpty(groupId)){
            return ServerResponse.createByErrorMessage("团id为空");
        }
        HGuideTravelGroup entity = hGuideTravelGroupMapper.selectByTravelGroupId(groupId);
        if (entity==null){
            return ServerResponse.createByErrorMessage("没有找到团导游关联信息");
        }
        return ServerResponse.createBySuccess(entity);
    }

    



}
